package com.jjlin.chapter_5;

import java.util.*;

public class CD99{

    //在有序但是含有空的数组中查找字符串(二分查找)
    public static int getIndex(String[] s, String str){
        if(s == null || s.length == 0 || str == null)
            return -1;
        int left = 0, right = s.length - 1;
        int mid = 0, res = -1, i;
        while(left <= right){
            mid = left + ((right - left) >> 1); //注意>>的优先级
            if(s[mid] != null && s[mid].equals(str)){ //s[mid]等于str，则继续搜索s[left, mid- 1]
                res = mid;
                right = mid - 1;
            }else if(s[mid] != null){
                if(s[mid].compareTo(str) < 0) //s[mid]小于str
                    left = mid + 1;
                else //s[mid]大于str
                    right = mid - 1;
            }else{ //s[mid]为null
                i = mid;
                while(s[i] == null && --i >= left); //查找left左边不为null的s[i]
                if(i < left || s[i].compareTo(str) < 0)  //如果i在left左边或者s[i]小于str,则s[left, mid]不符合要求
                    left = mid + 1;
                else{ //s[i]大于等于str
                    res = s[i].equals(str) ? i : res; //等于则记录s[i]位置
                    right = i - 1;
                }
            }
        }
        return res;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        String str = sc.nextLine();
        String[] s = new String[n];
        for(int i = 0; i < n; i++){
            String tmp = sc.nextLine();
            s[i] = tmp.equals("0") ? null : tmp;
        }
        System.out.print(getIndex(s, str));
    }
}
